package com.tequila.core.service.impl;

import com.google.common.collect.Lists;
import com.tequila.core.dao.AppResourcesDao;
import com.tequila.core.service.AppResourcesService;
import com.tequila.domain.dto.AppResourcesDto;
import com.tequila.domain.entity.AppResources;
import com.tequila.domain.query.AppResourcesQuery;
import fe.core.Assert;
import fe.core.BeanHelper;
import fe.core.Pagination;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AppResourcesServiceImpl implements AppResourcesService {
    public static final Logger logger = LoggerFactory.getLogger(AppResourcesServiceImpl.class);

    @Resource
    private AppResourcesDao appResourcesDao;

    @Override
    public Pagination<AppResourcesDto> queryPageListByParam(AppResourcesQuery query) {
        Assert.assertNotNull(query);
        int total = appResourcesDao.queryPageCountByParam(query);

        List<AppResourcesDto> list = Lists.newArrayList();
        if (total > 0) {
            list = appResourcesDao.queryPageListByParam(query);
        }
        return new Pagination<>(query, list, total);
    }

    @Override
    public AppResourcesDto queryById(Long id) {
        Assert.assertNotNull(id,"id不能为空!");
        AppResources appResources = appResourcesDao.queryById(id);
        AppResourcesDto appResourcesDto = new AppResourcesDto();
        BeanHelper.copyProperties(appResourcesDto,appResources);
        return appResourcesDto;
    }

    @Override
    public List<AppResourcesDto> queryByIdList(List<Long> idList) {
        Assert.assertNotNull(idList,"idList不能为空!");
        return appResourcesDao.queryByIdList(idList);
    }

    @Override
    public List<AppResourcesDto> queryListByParam(AppResourcesQuery query) {
        Assert.assertNotNull(query,"query不能为空!");
        return appResourcesDao.queryListByParam(query);
    }


    @Override
    public Long insert(AppResources entity) {
        Assert.assertNotNull(entity,"entity不能为空!");
        appResourcesDao.insert(entity);
        return entity.getId();
    }

    @Override
    public Long save(AppResources entity) {
        Assert.assertNotNull(entity,"entity不能为空!");
        appResourcesDao.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public int updateById(AppResources param) {
        Assert.assertNotNull(param,"param不能为空!");
        Assert.assertNotNull(param.getId(),"id不能为空!");
        return appResourcesDao.updateById(param);
    }

    @Override
    public int updateSelectiveById(AppResources param) {
        Assert.assertNotNull(param,"param不能为空!");
        Assert.assertNotNull(param.getId(),"id不能为空!");
        return appResourcesDao.updateSelectiveById(param);
    }

    @Override
    public int deleteById(Long id) {
        Assert.assertNotNull(id,"id不能为空!");
        return appResourcesDao.deleteById(id);
    }

    @Override
    public int deleteByIdList(List<Long> idList) {
        Assert.assertNotNull(idList,"idList不能为空!");
        return appResourcesDao.deleteByIdList(idList);
    }
}
